<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <title><%=@page_title%></title>
  <style>
    html, body {font-family:Arial,Verdana;}
    label {font-weight:bold;font-size:medium;}
    h1 {font-size:large;}
  </style>
  <script type="text/javascript">
    function changePath()
    {
        path_id = document.getElementById("path_id").value;
        document.getElementById("new_path").style.display = path_id == -1 ? "block" : "none";
        return false;
    }
    function validate()
    {
        var props = 'width=230, height=600, left=50, top=50, resizable=yes, scrollbars=yes, status=yes, location=yes, menubar=yes, toolbar=yes, directories=yes';
        
        // page title
        page_title = document.getElementById("step_title").value;
        if (page_title == "")
        {
            alert("Please enter a title for your page.");
            return false;
        }
        // page address
        page_uri = document.getElementById("step_uri").value;
        if (page_uri == "")
        {
            alert("Please enter the address of the page to add.");
            return false;
        }
        // selected path
        path_id = document.getElementById("path_id").value;
        if (path_id == 0)
        {
            alert("Please choose a path to add the page to.");
            return false;
        }
        // a new path was selected
        else if (path_id == -1)
        {
            // get the title for the new path
            new_path_title = document.getElementById("path_title").value;
            if (new_path_title == "")
            {
                alert("Please enter a title for your new path.");
                return false;
            }
            var browsePage = window.open('', 'browse_page', props);
            browsePage.focus();
            theForm = document.getElementById('add_page');
            theForm.target='browse_page';
            theForm.submit();
            document.location = page_uri;
        }
        else
        {
            var browsePage = window.open('/paths/delayed_browse/' + path_id, 'browse_page', props);
            browsePage.focus();
        }
        return true;
    }
    </script>
</head>
<body>
  <div id="header">
    <div id="logo"><a href="/" title="Go to Make A Path home page"><img src="/images/logo.gif" border="0"></a></div>
  </div>
  <div id="content">
    <%= error_messages_for :path, :step %>
    <div id="body-container">
        
        <%= form_tag({:action => "append_page"}, {:onSubmit => "return validate()", :name => "add_page", :id => "add_page"}) %>
        <table style="margin:12px">  
        <tr>
            <td><label for="site_title">Title</label>:</td>
            <td><%= text_field(:step, :title, :size => 100) %></td>
        </tr>    
        <tr>
            <td><label for="site_uri">Address</label>:</td>
            <td><%= text_field(:step, :uri, :size => 100) %></td>
        </tr>    
        <tr>
            <td><label for="path">Path</label>:</td>
            <td>
                <select id="path_id" name="path[id]" style="width:626px" onchange="return changePath();">
                  <option value="0">&lt;choose a path&gt;</option>
                  <%= options_from_collection_for_select(@paths, "id", "title", @most_recent_path_id) %>
                  <option value="-1" <%= @paths.length == 0 ? "selected=\"true\"" : "" %>>&lt;new path&gt;</option>
                </select>
            </td>
        </tr>    
        <tr>
            <td></td>
            <td><div id="new_path" style="<%= @paths.length != 0 ? 'display:none;' : '' %>margin-top:6px;"><label for="path_title">Path Title</label>: <%= text_field("path", "title", :size => 80) %></div></td>
        </tr>
        <tr>
            <td></td><td align="center"><img src="<%= Link.cache_thumbnail(@step.uri) %>" /></td>
        </tr>
        <tr>
            <td></td><td align="center"><%= submit_tag "Add Page to Path", :style => "font-size:18px;" %></td>
        </tr>
        </table>
    
        <%= end_form_tag %>
        
      </div>
  </div>
</body>
</html>
  